from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from contractsign.models import SoftContract, HardContract
from softedit.models import SoftAdContent

@login_required
def review_dashboard(request):
    if request.user.role != 'manager':
        return redirect('/')

    hard_contracts = HardContract.objects.all()
    soft_contracts = SoftContract.objects.all()
    ad_contents = SoftAdContent.objects.all()
    hard_ad_contents = hard_contracts
    for h in hard_ad_contents:
        print(h.status)
    return render(request, 'review_dashboard.html', {
        'hard_contracts': hard_contracts,
        'soft_contracts': soft_contracts,
        'ad_contents': ad_contents,
        'hard_ad_contents': hard_ad_contents
    })

from django.shortcuts import get_object_or_404
from softedit.models import SoftAdContent

@login_required
def approve_ad_content(request, content_id):
    if request.user.role != 'manager':
        return redirect('/')

    content = get_object_or_404(SoftAdContent, id=content_id)
    content.status = 'approved'
    content.save()
    return redirect('review_dashboard')

@login_required
def reject_ad_content(request, content_id):
    if request.user.role != 'manager':
        return redirect('/')

    content = get_object_or_404(SoftAdContent, id=content_id)
    content.status = 'rejected'
    content.save()
    return redirect('review_dashboard')

from django.shortcuts import get_object_or_404
from softedit.models import SoftAdContent

@login_required
def approve_ad_content(request, content_id):
    if request.user.role != 'manager':
        return redirect('/')

    content = get_object_or_404(SoftAdContent, id=content_id)
    content.status = 'approved'
    content.save()
    return redirect('review_dashboard')

@login_required
def reject_ad_content(request, content_id):
    if request.user.role != 'manager':
        return redirect('/')

    content = get_object_or_404(SoftAdContent, id=content_id)
    content.status = 'rejected'
    content.save()
    return redirect('review_dashboard')
